package com.ychong.ychongwidget.ui

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.ychong.library.dialog.BottomPlateKeyBoardDialog
import com.ychong.ychongwidget.R
import com.ychong.ychongwidget.databinding.ActivityYchPlateKeyboardViewBinding

class YCHPlateKeyBoardViewActivity : AppCompatActivity() {
    private var binding: ActivityYchPlateKeyboardViewBinding? = null
    private var textList:MutableList<String> = ArrayList()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_ych_plate_keyboard_view)

        binding!!.keyboardBtn.setOnClickListener {
            showHideKeyBoard()
        }
    }

    /**
     * 显示隐藏键盘
     */
    private var bottomPlateKeyBoardDialog: BottomPlateKeyBoardDialog? = null

    private fun showHideKeyBoard() {
        if (bottomPlateKeyBoardDialog == null) {
            bottomPlateKeyBoardDialog = BottomPlateKeyBoardDialog(this)
        }
        if (bottomPlateKeyBoardDialog!!.isShowing) {
            if (bottomPlateKeyBoardDialog != null) {
                bottomPlateKeyBoardDialog!!.dismiss()
            }
        } else {
            bottomPlateKeyBoardDialog!!.setKeyBoardListener(object :
                BottomPlateKeyBoardDialog.KeyBoardListener {
                override fun input(num: String) {
                    textList.add(num)
                    binding!!.showTv.text = textList.toString()
                }

                override fun remove() {
                   if (textList.isNotEmpty()){
                      textList.removeAt(textList.size-1)
                   }
                    binding!!.showTv.text = textList.toString()
                }

                override fun clear() {
                  textList.clear()
                    binding!!.showTv.text = textList.toString()

                }

                override fun complete() {

                }

            }).build()
        }

    }
}